<template>
  <basic-form
    :showAlert="false"
    message=""
    :formInfos="s_FormInfo"
    :formDatas="s_formDatas"
    :rules="s_rules"
    :buttonText="isEdit ? ['保存修改'] : []"
    :btnCusStyle="{ boxShadow: 'none' }"
    :isInline="true"
    @onSubmit="onSubmit"
  ></basic-form>
</template>

<script>
import basicForm from '../common/basicForm'
import { getInfoByPid, saveInfo } from './saleDelivery'
export default {
  components: {
    basicForm
  },
  props: {
    formDatas: {
      type: Object
    }
  },
  watch: {
    formDatas: {
      //深度监听，可监听到对象、数组的变化
      handler(val, oldVal) {
        console.log('监听formDatas', val, oldVal)
        this.s_formDatas = Object.assign(this.s_formDatas, val)
      },
      deep: true //true 深度监听
    }
  },
  data() {
    return {
      isEdit: false,
      s_FormInfo: [
        // { label: '销售单号', name: 'saleOrderNo', type: 'input',isDisabled:true, placeholder: '请输入销售单号' },
        { label: '配送单号', name: 'deliveryOrderNo', type: 'input', isDisabled: true, placeholder: '请选择配送单号' },
        {
          label: '配送单名称',
          name: 'deliveryOrderName',
          type: 'input',
          isDisabled: true,
          placeholder: '请选择配送单名称'
        },
        // { label: '是否关联多个订单', name: 'multipleOrder', type: 'input',isDisabled:true, placeholder: '是否关联多个订单' },
        // { label: '关联订单', name: 'associatedOrder', type: 'input',isDisabled:true, placeholder: '关联订单' },
        // { label: '物流关联单号', name: 'logisticsNo', type: 'input',isDisabled:true, placeholder: '请输入物流关联单号' },
        {
          label: '送货类型',
          name: 'deliveryType',
          type: 'dicselect',
          dicName: 'deliveryType',
          isDisabled: true,
          placeholder: '请选择送货类型'
        },
        { label: '寄件人姓名', name: 'sender', type: 'input', isDisabled: true, placeholder: '请输入寄件人姓名' },
        {
          label: '寄件人联系电话',
          name: 'senderTel',
          type: 'input',
          isDisabled: true,
          placeholder: '请输入寄件人联系电话'
        },
        {
          label: '寄件人证件类型',
          name: 'senderCertificateType',
          type: 'input',
          isDisabled: true,
          placeholder: '请输入寄件人证件类型'
        },
        {
          label: '寄件人证件号码',
          name: 'senderCertificateNo',
          type: 'input',
          isDisabled: true,
          placeholder: '请输入寄件人证件号码'
        },
        { label: '收件人姓名', name: 'receiver', type: 'input', isDisabled: true, placeholder: '请输入收件人姓名' },
        {
          label: '收件人联系电话',
          name: 'receiverTel',
          type: 'input',
          isDisabled: true,
          placeholder: '请输入收件人联系电话'
        },
        { label: '收件地址', name: 'receiverAddr', type: 'input', isDisabled: true, placeholder: '请输入收件地址' },
        { label: '物流方', name: 'logistics', type: 'input', isDisabled: true, placeholder: '请输入物流方' },
        { label: ['保存', '重置'], type: 'botton' }
      ],
      s_formDatas: {
        sysSeq: 0,
        pid: null,
        saleOrderNo: null,
        deliveryOrderNo: null,
        deliveryOrderName: null,
        multipleOrder: null,
        associatedOrder: null,
        deliveryType: null,
        sender: null,
        senderTel: null,
        senderCertificateType: null,
        senderCertificateNo: null,
        receiver: null,
        receiverTel: null,
        receiverAddr: null,
        logisticsNo: null,
        logistics: null
      },
      s_rules: {
        sender: [{ required: true, message: '寄件人姓名必填', trigger: 'blur' }],
        senderTel: [{ required: true, message: '寄件人联系电话必填', trigger: 'blur' }],
        receiver: [{ required: true, message: '收件人姓名必填', trigger: 'blur' }],
        receiverTel: [{ required: true, message: '寄件人联系电话必填', trigger: 'blur' }],
        receiverAddr: [{ required: true, message: '收件地址必填', trigger: 'blur' }]
      }
    }
  },
  mounted() {
    this.s_formDatas = Object.assign(this.s_formDatas, this.formDatas)
  },
  methods: {
    onEdit() {
      this.isEdit = true
      for (let item of this.s_FormInfo) {
        if (item.name == 'deliveryOrderNo') {
          item.isDisabled = true
        } else {
          item.isDisabled = false
        }
      }
    },
    onCancelEdit(){
      this.isEdit = false
      for (let item of this.s_FormInfo) {
        item.isDisabled = true
      }
    },
    // 模态详细框提交按钮
    onSubmit(val) {
      
      this.saveObjInfo(val)
    },
    // 保存详细信息
    async saveObjInfo(val) {
      let key = 'edit'
      this.$message.loading({ content: '提交中', key ,duration: 0})
      let res = await saveInfo(val)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.onCancelEdit()
        this.$message.success({ content: '修改成功', key, duration: 2 })
        this.$emit("onSave")
      } else {
        this.$message.success({ content: '修改失败', key, duration: 2 })
      }
    }
  }
}
</script>

<style></style>
